﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gChartSharp
{
    /// <summary>
    /// http://code.google.com/apis/chart/#axes_labels
    /// </summary>
    public class AxisLabelParam : IChartParam
    {

        /// <summary>
        /// The name of the API
        /// </summary>
        public string Name { get { return "chxl"; } }


        /// <summary>
        /// A list of data series - label pairs
        /// </summary>
        /// <remarks>
        /// i.e. Dictionary<0, new string[] { "Label1", "Label2" }>
        /// produces 0:|Label1|Label2 
        /// </remarks>
        public Dictionary<int, string[]> Labels 
        {
            get { return mLabels ?? (mLabels = new Dictionary<int, string[]>()); }
            set { mLabels = value; }
        }
        private Dictionary<int, string[]> mLabels;


        /// <summary>
        /// The default constructor
        /// </summary>
        public AxisLabelParam() { }


        /// <summary>
        /// Render the text of the API
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(String.Format("&{0}=", this.Name));

            foreach (KeyValuePair<int, string[]> kv in this.Labels)
            {
                // only render the KeyValuePair if there is at least one label for the specified series
                if (kv.Value.Count() > 0 )
                {
                    sb.Append(String.Format("{0}:|", kv.Key));

                    foreach (string label in kv.Value)
                        sb.Append(String.Format("{0}|", label));
                }
            }

            // remove last '|'
            sb.Remove(sb.ToString().LastIndexOf('|'), 1);

            return sb.ToString();
        }

    }


    public enum AxisLabelType
    {
        /// <summary>
        /// Bottom
        /// </summary>
        x, 

        /// <summary>
        /// Top
        /// </summary>
        t,

        /// <summary>
        /// Left
        /// </summary>
        y,

        /// <summary>
        /// Right
        /// </summary>
        r
    }
}
